package com.tencent.sr.iris.activity.service.convert;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.tencent.sr.iris.activity.interfaces.request.acticity.ActivityStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.ActivityUserStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.AwardStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.LongTermAwardStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.TaskRecordRequest;
import com.tencent.sr.iris.activity.interfaces.request.task.TaskIncomeRequest;
import com.tencent.sr.iris.activity.interfaces.response.activity.AwardStaticResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.LongTermAwardStaticResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Arrays;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * @author nixiaolin
 * @date 2022/7/22 10:56
 */
@Mapper(componentModel = "spring", imports = {Date.class, Objects.class, Optional.class, DateUtil.class,
        NumberUtil.class, Arrays.class})
public interface AwardStaticConvert {

    AwardStaticRequest buildFromLongTermAwardStaticRequest(LongTermAwardStaticRequest request);

    @Mapping(target = "startTime", expression = "java(NumberUtil.isLong(request.getStartTime()) && request.getStartTime() != null ? Long.valueOf(request.getStartTime()) : null)")
    @Mapping(target = "endTime", expression = "java(NumberUtil.isLong(request.getEndTime()) && request.getEndTime() != null ? Long.valueOf(request.getEndTime()) : null)")
    AwardStaticRequest buildFromTaskIncomeRequest(TaskIncomeRequest request);

    LongTermAwardStaticResponse buildLongTermAwardStaticResponse(AwardStaticResponse response);

    @Mapping(target = "userTaskStatus", expression = "java(Optional.ofNullable(request.getUserTaskStatus()).map(i -> Arrays.asList(i)).orElse(null))")
    @Mapping(target = "estimateUserTaskStatus", expression = "java(Optional.ofNullable(request.getEstimateUserTaskStatus()).map(i -> Arrays.asList(i)).orElse(null))")
    TaskRecordRequest buildFromAwardStaticRequest(AwardStaticRequest request);

    TaskRecordRequest buildFromActivityUserStaticRequest(ActivityUserStaticRequest request);

    TaskRecordRequest buildTaskRecordRequestFromLongTermAwardStaticRequest(LongTermAwardStaticRequest request);

    @Mapping(target = "startTime", expression = "java(NumberUtil.isLong(request.getStartTime()) ? Long.valueOf(request.getStartTime()) : null)")
    @Mapping(target = "endTime", expression = "java(NumberUtil.isLong(request.getEndTime()) ? Long.valueOf(request.getEndTime()) : null)")
    TaskRecordRequest buildTaskRecordRequestFromTaskIncomeRequest(TaskIncomeRequest request);

    /**
     * ActivityUserStaticRequest -> AwardStaticRequest
     * @param activityUserStaticRequest request
     * @return  AwardStaticRequest
     */
    AwardStaticRequest activityUserStaticRequest2AwardStaticRequest(ActivityStaticRequest activityUserStaticRequest);

    /**
     * ActivityUserStaticRequest -> ActivityUserStaticRequest
     * @param activityUserStaticRequest activityUserStaticRequest
     * @return ActivityUserStaticRequest
     */
    ActivityUserStaticRequest activityUserStaticRequest2ActivityUserStaticRequest(ActivityStaticRequest activityUserStaticRequest);

    /**
     * ActivityUserStaticRequest -> TaskRecordRequest
     * @param activityUserStaticRequest activityUserStaticRequest
     * @return TaskRecordRequest
     */
    TaskRecordRequest activityUserStaticRequest2TaskRecordRequest(ActivityStaticRequest activityUserStaticRequest);
}
